
package instrumentation;


public class CoverageBranchTarget  {

	/** the ID of the targeted branch. */
	private int branchId;
	private String cName="";
	private  String mName="";
	private boolean isMNamePublic;
	private String fName_1;
	private String fName_2;
	private String cValue_1;
	private String cValue_2;
	private String callee_1;
	private String callee_2;

	private	String mCall;
	private	String mClase;
	private String  argsField;
	/** The distance to reach the target */
	private double distance;

	// HillClimbing number of attempt for each target
	private int attempt;
	public void setAttempt(int attempt){
		this.attempt=attempt;
	}
	public int getAttempt(){
		return this.attempt;
	}
	public CoverageBranchTarget(int branchId) {
		this.branchId = branchId;
		distance = Float.POSITIVE_INFINITY;
		attempt=0;
	}
	public void setDistance(double d) {
	//	if(distance >d) 
			distance = d;
	}
	public void setBranchId(int branchId) {
		this.branchId = branchId;
	}
	public int getBranchId() {
		return branchId;
	}
	
//	public List<Method> getMList(){
//		return this.mList;
//	}
	public void setIfCondition(String cName,String mName,boolean isMPublic, 
			String fName_1, String fName_2,String cValue_1,String cValue_2,
			String callee_1,String callee_2,
			String mCall,String mClase,String argsField) {
		this.cName=cName;
		this.mName=mName;
		this.isMNamePublic=isMPublic;
		this.fName_1=fName_1;
		this.fName_2=fName_2;
		this.cValue_1=cValue_1;
		this.cValue_2=cValue_2;

		this.callee_1=callee_1;
		this.callee_2=callee_2;

		this.mCall=mCall ;
		this.mClase=mClase; 
		this.argsField=argsField;
	}
	public Class<?> getcName(){
		try{
		return Class.forName(this.cName);
		} catch (ClassNotFoundException e) {
			
		}
		return null;
	}
	public String getmName() {
		return this.mName;
	}
	public boolean getisMNamePublic() {
		return this.isMNamePublic;
	}
	public String getfName_1() {
		return this.fName_1.trim();
	}
	public String getfName_2() {
		return this.fName_2.trim();
	}
	public String getcValue_1() {
		return this.cValue_1;
	}
	public String getcValue_2() {
		return this.cValue_2;
	}
	public void setcValue_2(String cValue2) {
		//HillClimbing.recommendPredicateValue
		 cValue_2=cValue2;
	}
	public String getCallee_1() {
		return this.callee_1;
	}
	public String getCallee_2() {
		return this.callee_2;
	}

	public String getmCall() {
		return this.mCall;
	}
	public String getType() {
		return this.mClase;
	}
	public String getArgsField() {
		return this.argsField;
	}

	/**
	 * Returns the quality: lower is better
	 */
	public float getQuality() {
		if(distance == Float.POSITIVE_INFINITY) return Float.POSITIVE_INFINITY;
		if(distance ==-1) return Float.NEGATIVE_INFINITY;
	//	return (float) (1.0/(distance+0.125));
		return (float) (distance/(distance+1.0));
	}

	@Override
	public String toString() {
		String predicate;
		predicate = "[branch:" + branchId + "] quality: " + getQuality() +" c:"+ getcName()+ " m:" +getmName() + " isPublic:"+ getisMNamePublic() + " f1:"+ getfName_1() ;
		predicate += " f2:"+ getfName_2() + " v1:"+ getcValue_1()+ " v2:"+ getcValue_2();
		predicate += " callee1: "+ getCallee_1()+ "  callee_2: "+ getCallee_2() ;
		predicate +=  " mCall:"+ getmCall() + " Type:"+ getType() ; 
		predicate +=" args: "+ getArgsField();
		return predicate;
	}
}